//
//  MenuBase.swift
//  SwiftTest
//
//  Created by 北京 on 2020/12/9.
//  Copyright © 2020 QiKai. All rights reserved.
//

import UIKit


let screenWidth = UIScreen.main.bounds.size.width
let screenHigth = UIScreen.main.bounds.size.height

class MenuBase: UIView {
  
    
    
    var commontView:UIView!
    var commontHeight:CGFloat = screenHigth/2{
        didSet{
            commontView.snp.updateConstraints { (make) in
                make.height.equalTo(self.commontHeight)
            }
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.creatBaseUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func creatBaseUI(){
        self.layer.opacity = 0.0//默认隐藏
        
        self.backgroundColor = UIColor.red;
        commontView = UIView.init()
        self.addSubview(commontView)
        commontView.backgroundColor = UIColor.green
        commontView.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(commontHeight)
        }
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(dissMissView))
        self.addGestureRecognizer(tap)
        
    }
    @objc func cancelAction(){
        self.dissMissView()
    }
    func showView()  {
//        UIApplication.shared.keyWindow?.addSubview(self)
//        self.center = (UIApplication.shared.keyWindow?.center)!
        UIApplication.shared.keyWindow?.bringSubviewToFront(self)
        self.layer.opacity = 1.0
    }
    @objc func dissMissView() {
        self.layer.opacity = 0.0
    }

}
